
axios.defaults.baseURL = "http://127.0.0.1:8080";
axios.defaults.timeout = 10000;
axios.defaults.withCredentials = false
axios.defaults.headers = {
  "Content-Type": "application/json"
};

// 添加请求拦截器
axios.interceptors.request.use(
  config => {
    // let flag = getLocalStorage("token")
    // if (flag) {
    //   config.headers['token'] = flag
    // }
    return config
  },
  error => {
      console.log(error) 
      Promise.reject(error)
  }
)

// 添加响应拦截器
axios.interceptors.response.use(
  response => {
    console.log(response)
    return response
    if(response.status==200){
      if(response.data.status == "0"){
        return Promise.reject(response)
      }
      if(response.data.status == "1"&&response.data.message!=""){
        
          return response
      }
      if(response.data.status == "1"&&response.data.message==""){
          return response
      }
      if(response.data.status == "403"){
        
        window.location = "login.html"
       
        return Promise.reject(response)
      }
   
          

    }
  },
  error => {
      console.log('err' + error)
      return Promise.reject(error)
  }
)
 function get(url, params){    
  return new Promise((resolve, reject) =>{        
      axios.get(url, {            
          params: params        
      }).then(res => {
          resolve(res);
      }).catch(err =>{
          reject(err.data)        
  })    
});}
function post(url, params) {
  return new Promise((resolve, reject) => {
       axios.post(url, params)
      .then(res => {
          resolve(res);
      })
      .catch(err =>{
          reject(err.data)
      })
  });
}
function put(url, params) {
  return new Promise((resolve, reject) => {
       axios.put(url, params)
      .then(res => {
          resolve(res.data);
      })
      .catch(err =>{
          reject(err.data)
      })
  });
}
